﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register Src="~/Views/Shared/Textbox.ascx" TagName="textbox" TagPrefix="uc" %>
<%@ Register Src="~/Views/Shared/Button.ascx" TagName="button" TagPrefix="uc" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Đăng ảnh
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
<link href="/Content/scroller.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/scroller.js"></script>
<script src="/Scripts/jquery.form.js"></script>
<script>
    $(document).ready(function (e) {
        $(".headermenu_item a").eq(4).addClass("active");
        createScoller("categorylist");
        createScoller("subcategorylist");
        categoryHandle(".scroller p");
        formUploadHandle();
        $("#txtfilebrowser, #btnfilebrowser").click(function (e) {
            $("#myfiles").trigger("click");
        });
        $("#myfiles").bind("change", function (e) {
            var s = "";
            for (var i = 0; i < $(this).get(0).files.length; i++) {
                s += $(this).get(0).files[i].name;
                if (i < $(this).get(0).files.length - 1) {
                    s += ", ";
                }
            }
            $("#txtfilebrowser").val(s);
        });
    });

    function formUploadHandle() {

        $('form').ajaxForm({
            beforeSend: function () {
                var percentVal = '0%';
            },
            uploadProgress: function (event, position, total, percentComplete) {
                var percentVal = percentComplete + '%';
            },
            complete: function (xhr) {

                alert(xhr.responseText);
                //status.html(xhr.responseText);
            }
        });
    }

    function categoryHandle(elm) {
        $(elm).click(function (e) {
            $(this).parent("div").children("p").removeClass("selectedcat");
            $(this).addClass("selectedcat");
            var cat = $(this).attr("id").replace("Cat", "");
            if ($(this).parents(".dotpanel").attr("id") == "categorylist") {
                $("#subcategorylist .scroller_panel").html("");
                createScoller("subcategorylist");
                ajaxquery("/GetList/SubCategory", { "cat": cat }, function (data) {
                    $("#subcategorylist .scroller_panel").css({ "top": 0 });
                    $("#subcategorylist .scroller_panel").html(data);
                    createScoller("subcategorylist");
                    categoryHandle("#subcategorylist p");
                });
            }
        });
    }
</script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
    int lang = (int)ViewData["Language"];
%>
<div id="categorymenu">
    <div id="direction">
        <div class="rightarrow"></div>
        <div><%= Html.ActionLink("THƯ VIỆN ẢNH","Index","Category") %></div>
        <div class="rightarrow"></div>
        <div><%= Html.ActionLink("ĐĂNG ẢNH","Upload","Image") %></div>
    </div>
	<div class="clear"></div>
</div>

<div id="uploadpanel">
    <div class="left">
        <div class="title">Chọn chủ đề</div>
        <div id="categorylist" class="dotpanel scrollery scroller">
        <div class="scrollbar">
            <div class="scrollbar_end"></div>
            <div class="scrollbar_thumb"><div class="scrollbar_thumb_end"></div></div>
        </div>
        <div class="scroller_view">
            <div class="scroller_panel">
<%
    List<VietImage.Models.Category> lst = new List<VietImage.Models.Category>();
    if (ViewData["CategoryList"] != null)
    {
        lst = (List<VietImage.Models.Category>)ViewData["CategoryList"];
    }
    VietImage.Models.Category selectedCat = null;
    if (ViewData["SelectedCategory"] != null)
    {
        selectedCat = (VietImage.Models.Category)ViewData["SelectedCategory"];
    }
    String s = "";
    String selected = "";
    foreach (VietImage.Models.Category cat in lst)
    {
        selected = "";
        if (ViewData["SelectedCategory"] != null)
        {
            if (selectedCat.ID == cat.ID || (!selectedCat.IsParent && selectedCat.Parents[0].ID == cat.ID))
            {
                selected = "class=\"selectedcat\"";
            }
        }
        s = "<p " + selected + " id=\"Cat" + cat.ID + "\">" + cat.GetDetail(lang).Name + "</p>";
        %>
                            <%= s %>
        <%
    }
%>        
            </div>
        </div>
        </div>
    </div>

    <div class="left">
        <div class="title">Chọn chủ đề con cần đăng</div>
        <div id="subcategorylist" class="dotpanel scrollery scroller">
        <div class="scrollbar">
            <div class="scrollbar_end"></div>
            <div class="scrollbar_thumb"><div class="scrollbar_thumb_end"></div></div>
        </div>
        <div class="scroller_view">
            <div class="scroller_panel">
<% 
    s = "";
    selected = "";
    lst = null;
    if (selectedCat == null)
    {
        lst = new List<VietImage.Models.Category>();
    }
    else if (selectedCat.IsParent)
    {
        lst = selectedCat.Children;
    }
    else{
        lst = selectedCat.Parents[0].Children;
    }
    foreach (VietImage.Models.Category cat in lst)
    {
        selected = "";
        if (selectedCat.ID == cat.ID)
        {
            selected = "class=\"selectedcat\"";
        }
        s = "<p " + selected + " id=\"SubCat" + cat.ID + "\">" + cat.GetDetail(lang).Name + "</p>";
        %>
                            <%= s%>
        <%
    }
%>
            </div>
        </div>
        </div>

        <div style="margin-top: 10px;" class="title">Hoặc tạo chủ đề con mới</div>
        <div id="newsubcategory" class="dotpanel">
            <div>Tên chùm ảnh</div>
            <uc:textbox ID="txtnewsubcategory" runat="server" />
            <uc:button Style="float: right;" Value="Tạo" runat="server" />
            <div class="clear"></div>
        </div>

    </div>

    <div style="float: left;">
    <form action="/Image/UploadImage" method="post" enctype="multipart/form-data">
        <div class="title">Nhập thông tin ảnh</div>
        <div id="uploadinfo" class="dotpanel">
            <div class="left">Chọn (các) ảnh cần đăng</div>
            <div class="clear"></div>

            <input type="file" style="display: none;" id="myfiles" name="myfile[]" multiple>


            <uc:textbox ID="txtfilebrowser" runat="server"/>
            <uc:button ID="btnfilebrowser" Value="CHỌN" runat="server" />
            <div class="clear"></div>

            <div class="left">Thông tin chung</div>
            <div class="clear"></div>
            <div class="left">Ngày chụp</div>
            <uc:textbox ID="Textbox1" runat="server"/>
            <div class="clear"></div>
            <div class="left">Địa điểm chụp</div>
            <div class="clear"></div>
            <div class="left location">Thành phố</div>
            <div class="combobox" value="">
                <div class="combobox_selected"></div>
                <div class="combobox_button"></div>
                <div class="combobox_items">
                    <div class="combobox_item" value="" ></div>
                </div>
            </div>
            <div class="clear"></div>
            <div class="left location">Quốc gia</div>
            <div class="combobox" value="">
                <div class="combobox_selected"></div>
                <div class="combobox_button"></div>
                <div class="combobox_items">
                    <div class="combobox_item" value="" ></div>
                </div>
            </div>
            <div class="clear"></div>
            <div class="left">Tác giả</div>
            <uc:textbox ID="Textbox2" runat="server"/>
            <div class="clear"></div>
            <div class="left">Từ khóa</div>
            <uc:textbox ID="Textbox3" runat="server"/>
            <div class="clear"></div>
            <div style="position: absolute; bottom: 170px; right: 10px;">
                <uc:button Type="submit" Value="Đăng" Style="width: 80px; float: right;" runat="server" />
                <div class="clear"></div>
            </div>
        </div>
    </form>
    </div>

</div>

</asp:Content>
